package com.academic_system.mapper;

import com.academic_system.model.MarkCondition;
import com.academic_system.model.Warning;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 20155884 王晓阳
 * @className : WarningDao
 * @Description
 **/
public interface WarningDao {
    /**
     * @Description 动态从Warning表查找学业警示
     * @author 20155884 王晓阳
     * @methodName selectWarning
     * @param markCondition
     * @returnType String
     **/
    @SelectProvider(type = WarningSqlProvider.class, method = "selectWarning")
    List<MarkCondition> selectWarning(MarkCondition markCondition);

    /**
     * @Description 给所修学分不足总学分一半的学生学业警告数置1，即添加学业警告
     * @author 20155884 王晓阳
     * @methodName addWarning
     * @param warning
     * @returnType int
     **/
    @Insert("insert into warning(warning_id,term_id,stu_info_id,warning_num) " +
           "values(NULL,#{termId},#{stuInfoId},#{warningNum})")
    int addWarning(Warning warning);

    /**
     * @Description 根据学期id ，学生id在Warning表查找学业警示
     * @author 20155884 王晓阳
     * @methodName selectWarning
     * @param warning
     * @returnType String
     **/
    @Select("select * from warning where term_id=#{warning.termId} and stu_info_id=#{warning.stuInfoId}")
    Warning selectWarningByIds(@Param("warning") Warning warning);

    /**
     * @param term_id
     * @Description 在courseterm表中按学期查询本学期所有课程的总学分
     * @author 20155884 王晓阳
     * @methodName findTotalCourseCredithour
     * @returnType Msg
     **/
    @Select("select sum(course_credithour)  from course_term,course where course_term.course_id=course.course_id and term_id=#{term_id}")
    int findTotalCourseCredithour(@Param("term_id") int term_id);

    /**
     * @param markCondition
     * @Description 查询学生的总学分
     * @author 20155884 王晓阳
     * @methodName findStuCredithour
     * @returnType Msg
     **/
    @SelectProvider(type = WarningSqlProvider.class, method = "findStuCredithour1")
    MarkCondition findStuCredithour1(MarkCondition markCondition);

    /**
     * @param warningId
     * @Description  删除学业警示
     * @author 20155884 王晓阳
     * @methodName deleteWarning
     * @returnType
     **/
    @Delete("delete from warning where warning_id=#{warningId}")
    int deleteWarning(@Param("warningId")int warningId);
}
